package com.example.demo.repository;

import com.example.demo.bean.UserBean;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;

/**
 * @author zhangbiao
 * @date 2020/6/25 11:00
 * @desc 描述
 */
public interface UserRepository extends JpaRepository<UserBean, String> {

    //https://blog.csdn.net/linzhiqiang0316/article/details/79177077  JPA查询大全

    /**
     * 相当于 select * from t_user where userName =? or password=?
     *
     * @param account
     * @param password
     * @return
     */
    @Query(value = "SELECT * FROM t_user WHERE account = ?1 AND password = ?2 AND sp_identity = ?3", nativeQuery = true)
    public UserBean findByAccountAndPassword(String account, String password,String spIdentity);

    public UserBean findByAccount(String account);

    public UserBean findByObjId(String userid);

    @Query(value = "SELECT * FROM t_user u ", nativeQuery = true)
    public Page<Map<String, Object>> findAllUser(Pageable pageable);

    public void deleteByObjId(String userid);

    @Query(value = "SELECT * FROM t_user WHERE sp_identity = '老师'", nativeQuery = true)
    public List<Map<String, Object>> findTeachers();

    @Query(value = "SELECT COUNT(*) FROM t_user WHERE sp_identity = '学生'", nativeQuery = true)
    public int findStudentCount();
}
